
local linkToActorPathButton = nil
local cameraPlayButton = nil
local cameraShakeSlider = nil
local closeButton = nil

local function CreateLabel(text, color, x,y, parent)
	local label = vgui.Create("DLabel", parent) 
	label:SetText(text) 
	label:SetTextColor(color) 
	label:SizeToContents()
	label:SetPos(x,y)
	return label
end

local WHITE = Color(255,255,255,255)
local ORANGE = Color(195,140,45,255)
local DARK_GREY = Color(16,16,16,255)
local GREY = Color(128,128,128,255)

local PADDING = 9
local THIN_PAD = 1
local ANCHOR_Y = PADDING
local ANCHOR_X = PADDING
local CAT_WIDTH = 100
local SEC_WIDTH = 300
local HEIGHT = 250
local TITLE_BAR_HEIGHT = 20
local BUTTON_DIMENSION = 64
local BUTTON_DIMENSION_SMALL = 32
local lastPropertiesSection = 1

local function CreateButton(text, clickFunction, width,height, darken, parent)
	local button = vgui.Create("DButton", parent) 
	button:SetText(text) 
	button:SetTextColor(WHITE) 
	if darken then
		button:SetColor(DARK_GREY)
    end
	button:SizeToContents()
	button:SetTextColorHovered(ORANGE) 
	button:SetSize(width,height)
	button:SetDrawBorder(false)
	button.DoClick = clickFunction
	return button
end

local function DisplayPropertiesSection(callingEntity, sectionPanel)
	
	local yPos = THIN_PAD
	local display = CreateLabel("Display:", GREY, PADDING,yPos,sectionPanel)
	yPos = yPos + display:GetTall()

	local showToolCheckbox = vgui.Create( "DCheckBoxLabel", sectionPanel )
	showToolCheckbox:SetPos(PADDING, yPos )
	showToolCheckbox:SetText( "Show 'Tool Gun'" )
	showToolCheckbox:SizeToContents()
	//showViewFinderCheckbox:SetConVar( "sbox_godmode" )
	showToolCheckbox:SetValue( 0 )
	yPos = yPos + showToolCheckbox:GetTall() + THIN_PAD

	local showNodeSettingsCheckbox = vgui.Create( "DCheckBoxLabel", sectionPanel )
	showNodeSettingsCheckbox:SetPos(PADDING, yPos )
	showNodeSettingsCheckbox:SetText( "Show node symbols" )
	showNodeSettingsCheckbox:SizeToContents()
	//showViewFinderCheckbox:SetConVar( "sbox_godmode" )
	showNodeSettingsCheckbox:SetValue( 0 )
	yPos = yPos + showNodeSettingsCheckbox:GetTall() + THIN_PAD

end

local function LoadCustomFrames(dimen,panel)

	local buttonTable = {}
	local FACE_DIR = "../materials/myproject/frames/"
	local headFn = file.Find(FACE_DIR .. "*.vmt")
	for _, fn in pairs(headFn) do
		local filename = string.sub(fn,1, string.len(fn) - 4)

		if filename != "widescreen" and filename != "scope" then
			local mateiralFilepath = "myproject/frames/" .. filename

			local button = vgui.Create( "DImageButton", panel) 
			button:SetMaterial( mateiralFilepath ) 
			button:SetSize(dimen,dimen)
			button.DoClick = function () 
				callingEntity.BaseClass.GetRootNode(callingEntity):SetNWString("framing_type", filename)
			end
			table.insert(buttonTable,button)
		end
	end

	return buttonTable

end

local function DisplayFramingSection(callingEntity, sectionPanel)

	local yPos = THIN_PAD
	local industry_templates = CreateLabel("Industry Templates:", GREY, PADDING,yPos,sectionPanel)
	yPos = yPos + industry_templates:GetTall()

	local normalFrameButton = vgui.Create("DImageButton", sectionPanel) 
	normalFrameButton:SetMaterial("gui/frame_tv")
	normalFrameButton:SetSize(BUTTON_DIMENSION,BUTTON_DIMENSION)
	normalFrameButton:SetPos(PADDING,yPos)
	normalFrameButton.DoClick = function () 
		LocalPlayer():ConCommand( "npc_mover_gun_entitIDfromclient " .. callingEntity:EntIndex())
		LocalPlayer():ConCommand( "npc_mover_gun_functIDfromclient " .. CatmullRomCams.SToolMethods.ActorMover.FUNCTION_ID_UPDATE_CAMERANODE)
		LocalPlayer():ConCommand( "npc_mover_gun_framing_type " .. "nil")
	end
	
	local widescreenFrameButton = vgui.Create("DImageButton", sectionPanel) 
	widescreenFrameButton:SetMaterial("gui/frame_widescreen")
	widescreenFrameButton:SetSize(BUTTON_DIMENSION,BUTTON_DIMENSION)
	widescreenFrameButton:SetPos(PADDING + BUTTON_DIMENSION + THIN_PAD + THIN_PAD,yPos)
	widescreenFrameButton.DoClick = function () 
		LocalPlayer():ConCommand( "npc_mover_gun_entitIDfromclient " .. callingEntity:EntIndex())
		LocalPlayer():ConCommand( "npc_mover_gun_functIDfromclient " .. CatmullRomCams.SToolMethods.ActorMover.FUNCTION_ID_UPDATE_CAMERANODE)
		LocalPlayer():ConCommand( "npc_mover_gun_framing_type " .. "widescreen")
	end
	
	local scopeFrameButton = vgui.Create("DImageButton", sectionPanel) 
	scopeFrameButton:SetMaterial("gui/frame_scope")
	scopeFrameButton:SetSize(BUTTON_DIMENSION,BUTTON_DIMENSION)
	scopeFrameButton:SetPos(PADDING + BUTTON_DIMENSION + THIN_PAD + THIN_PAD + BUTTON_DIMENSION + THIN_PAD + THIN_PAD,yPos)
	scopeFrameButton.DoClick = function () 
		LocalPlayer():ConCommand( "npc_mover_gun_entitIDfromclient " .. callingEntity:EntIndex())
		LocalPlayer():ConCommand( "npc_mover_gun_functIDfromclient " .. CatmullRomCams.SToolMethods.ActorMover.FUNCTION_ID_UPDATE_CAMERANODE)
		LocalPlayer():ConCommand( "npc_mover_gun_framing_type " .. "scope")

	end
	yPos = yPos + BUTTON_DIMENSION + PADDING

	local custom_frames = CreateLabel("Custom Frames:", GREY, PADDING,yPos,sectionPanel )
	yPos = yPos + custom_frames:GetTall() + THIN_PAD
	
	local customFrameButtons = LoadCustomFrames(BUTTON_DIMENSION,sectionPanel)
	local count = 0
	for _, frameButton in pairs(customFrameButtons) do

		local inter, frac = math.modf(sectionPanel:GetWide() / (PADDING + BUTTON_DIMENSION))
		local col = count % inter
		local line, ig = math.modf(count / inter)
		frameButton:SetPos(PADDING + (col * (THIN_PAD + BUTTON_DIMENSION)), (line * (THIN_PAD + BUTTON_DIMENSION)) + yPos)
	
		count = count + 1
		
	end
end

local function DisplayPlaybackSection(callingEntity, sectionPanel)

	local yPos = THIN_PAD
	local playback_control = CreateLabel("Playback Control:", GREY, PADDING,yPos,sectionPanel)
	yPos = yPos + THIN_PAD + playback_control:GetTall()
	
	local cameraPlayButton = vgui.Create( "DImageButton", sectionPanel) 
	cameraPlayButton:SetMaterial( "gui/control_play_final" ) 
	cameraPlayButton:SetSize(BUTTON_DIMENSION_SMALL,BUTTON_DIMENSION_SMALL)
	cameraPlayButton:SetPos(PADDING,yPos)
	cameraPlayButton.DoClick = function () 
		//Need to put the tool back into idle state so that its 'Think()' will process the
		//function request to 'play' the camera
		LocalPlayer():ConCommand( "npc_mover_gun_toolstate " .. CatmullRomCams.SToolMethods.ActorMover.TOOLSTATE_IDLE)
		LocalPlayer():ConCommand( "npc_mover_gun_entitIDfromclient " .. callingEntity:EntIndex())
		LocalPlayer():ConCommand( "npc_mover_gun_functIDfromclient " .. CatmullRomCams.SToolMethods.ActorMover.FUNCTION_ID_PLAY)
		//sectionPanel:SetVisible(false)
		sectionPanel:GetParent():SetVisible(false)
	end

	yPos = yPos + cameraPlayButton:GetTall() + PADDING

	local preview_control = CreateLabel("Preview Control:", GREY, PADDING, yPos, sectionPanel)
	yPos = yPos + preview_control:GetTall() + THIN_PAD

	local previewPlayButton = vgui.Create( "DImageButton", sectionPanel) 
	previewPlayButton:SetMaterial( "gui/control_play" ) 
	previewPlayButton:SetSize(BUTTON_DIMENSION_SMALL,BUTTON_DIMENSION_SMALL)
	previewPlayButton:SetPos(PADDING,yPos)
	
	local previewPauseButton = vgui.Create( "DImageButton", sectionPanel) 
	previewPauseButton:SetMaterial( "gui/control_pause" ) 
	previewPauseButton:SetSize(BUTTON_DIMENSION_SMALL,BUTTON_DIMENSION_SMALL)
	previewPauseButton:SetPos(PADDING + previewPlayButton:GetWide() + THIN_PAD, yPos)
	
	local cameraPreviewStopButton = vgui.Create( "DImageButton", sectionPanel) 
	cameraPreviewStopButton:SetMaterial( "gui/control_stop" ) 
	cameraPreviewStopButton:SetSize(BUTTON_DIMENSION_SMALL,BUTTON_DIMENSION_SMALL)
	cameraPreviewStopButton:SetPos(PADDING + previewPlayButton:GetWide() + THIN_PAD + previewPauseButton:GetWide() + THIN_PAD, yPos)
	yPos = yPos + cameraPreviewStopButton:GetTall() + PADDING
	
	local camera_range_control = CreateLabel("Camera Range Control:", GREY, PADDING, yPos, sectionPanel)
	yPos = yPos + camera_range_control:GetTall() + THIN_PAD

	local cameraRangeButton = vgui.Create( "DButton" , sectionPanel) 
	cameraRangeButton:SetText( "Mark Camera" ) 
	cameraRangeButton:SetPos( PADDING, yPos) 
	cameraRangeButton:SetSize( 150, 25 ) 
	cameraRangeButton.DoClick = function () 
		cameraRangeButton:SetSelected( !cameraRangeButton:GetSelected() )
	end
end

local function DisplayTimingSection(callingEntity, sectionPanel)

	local yPos = THIN_PAD
	local transition_duration = CreateLabel("Camera Transition:", GREY, PADDING,yPos,sectionPanel)
	yPos = yPos + THIN_PAD + transition_duration:GetTall()
	
	local transitionTimeSlider = vgui.Create( "DNumSlider", sectionPanel ) 
	transitionTimeSlider:SetPos( PADDING,yPos) 
	transitionTimeSlider:SetSize( sectionPanel:GetWide() - (PADDING * 2), 35 )
	transitionTimeSlider:SetText( "Duration" ) 
	transitionTimeSlider:SetMin( 0 )
	transitionTimeSlider:SetMax( 1000 )
	transitionTimeSlider:SetDecimals( 1 )
	transitionTimeSlider:SetConVar( "npc_mover_gun_duration_transition" )
	yPos = yPos + transitionTimeSlider:GetTall() + PADDING

	local transition_duration = CreateLabel("Pause at Node:", GREY, PADDING,yPos,sectionPanel)
	yPos = yPos + THIN_PAD + transition_duration:GetTall()
	
	local nodeTimeSlider = vgui.Create( "DNumSlider", sectionPanel ) 
	nodeTimeSlider:SetPos( PADDING,yPos ) 
	nodeTimeSlider:SetSize( sectionPanel:GetWide() - (PADDING * 2), 35 )
	nodeTimeSlider:SetText( "Wait time" ) 
	nodeTimeSlider:SetMin( 0 )
	nodeTimeSlider:SetMax( 1000 )
	nodeTimeSlider:SetDecimals( 1 )
	nodeTimeSlider:SetConVar( "npc_mover_gun_duration_wait" )
end

local function DisplayDisplaySection(callingEntity, sectionPanel)

	local yPos = THIN_PAD
	local playback_control = CreateLabel("Assistance:", GREY, PADDING,yPos,sectionPanel)
	yPos = yPos + THIN_PAD + playback_control:GetTall()
	
	LocalPlayer():ConCommand(string.format("npc_mover_gun_show_view_finder %u",callingEntity:GetNWInt("show_view_finder")))
	local showViewFinderCheckbox = vgui.Create( "DCheckBoxLabel", sectionPanel )
	showViewFinderCheckbox:SetPos(PADDING, yPos )
	showViewFinderCheckbox:SetText( "Show 'View Finder'" )
	showViewFinderCheckbox:SizeToContents()
	showViewFinderCheckbox:SetConVar( "npc_mover_gun_show_view_finder" )
	yPos = yPos + showViewFinderCheckbox:GetTall() + PADDING

	local link_display = CreateLabel("Link Display:", GREY, PADDING,yPos,sectionPanel)
	yPos = yPos + THIN_PAD + link_display:GetTall()
		
	local showActorPathLinksCheckbox = vgui.Create( "DCheckBoxLabel", sectionPanel )
	showActorPathLinksCheckbox:SetPos(PADDING, yPos )
	showActorPathLinksCheckbox:SetText( "Show pathway event links" )
	showActorPathLinksCheckbox:SizeToContents()
	//showViewFinderCheckbox:SetConVar( "sbox_godmode" )
	showActorPathLinksCheckbox:SetValue( 0 )
	yPos = yPos + showActorPathLinksCheckbox:GetTall()

	local showPropLinksCheckbox = vgui.Create( "DCheckBoxLabel", sectionPanel )
	showPropLinksCheckbox:SetPos(PADDING, yPos )
	showPropLinksCheckbox:SetText( "Show prop links" )
	showPropLinksCheckbox:SizeToContents()
	//showViewFinderCheckbox:SetConVar( "sbox_godmode" )
	showPropLinksCheckbox:SetValue( 0 )
	yPos = yPos + showPropLinksCheckbox:GetTall()
end

local function DisplayPhenomenaSection(callingEntity, sectionPanel)

	local yPos = THIN_PAD
	local zoom_fov = CreateLabel("Camera Zoom/Feild of view:", GREY, PADDING,yPos,sectionPanel)
	yPos = yPos + THIN_PAD + zoom_fov:GetTall()

	local cameraZoomSlider = vgui.Create( "DNumSlider", sectionPanel ) 
	cameraZoomSlider:SetPos( PADDING,yPos ) 
	cameraZoomSlider:SetSize( sectionPanel:GetWide() - (2 * PADDING), 33 )
	cameraZoomSlider:SetText( "Zoom" ) 
	cameraZoomSlider:SetMin( 0 )
	cameraZoomSlider:SetMax( 170 )
	cameraZoomSlider:SetDecimals( 1 )
	cameraZoomSlider:SetConVar( "npc_mover_gun_camera_zoom" )
	yPos = yPos + PADDING + cameraZoomSlider:GetTall()

	local camera_shake = CreateLabel("Camera Shake:", GREY, PADDING,yPos,sectionPanel)
	yPos = yPos + THIN_PAD + camera_shake:GetTall()

	local randomShake = vgui.Create( "DImageButton", sectionPanel) 
	randomShake:SetMaterial( "gui/sharp_shake" ) 
	randomShake:SetSize(BUTTON_DIMENSION_SMALL,BUTTON_DIMENSION_SMALL)
	randomShake:SetPos(PADDING,yPos)
	randomShake.DoClick = function () 
		LocalPlayer():ConCommand( "npc_mover_gun_entitIDfromclient " .. callingEntity:EntIndex())
		LocalPlayer():ConCommand( "npc_mover_gun_functIDfromclient " .. CatmullRomCams.SToolMethods.ActorMover.FUNCTION_ID_UPDATE_CAMERANODE)
		LocalPlayer():ConCommand( "npc_mover_gun_shake_type 0")
	end
	
	local smoothShake = vgui.Create( "DImageButton", sectionPanel) 
	smoothShake:SetMaterial( "gui/smooth_shake" ) 
	smoothShake:SetSize(BUTTON_DIMENSION_SMALL,BUTTON_DIMENSION_SMALL)
	smoothShake:SetPos(PADDING + randomShake:GetWide() + THIN_PAD, yPos)
	smoothShake.DoClick = function () 
		LocalPlayer():ConCommand( "npc_mover_gun_entitIDfromclient " .. callingEntity:EntIndex())
		LocalPlayer():ConCommand( "npc_mover_gun_functIDfromclient " .. CatmullRomCams.SToolMethods.ActorMover.FUNCTION_ID_UPDATE_CAMERANODE)
		LocalPlayer():ConCommand( "npc_mover_gun_shake_type 1")
	end
 	yPos = yPos + smoothShake:GetTall() + PADDING
	
	local camera_shake_param = CreateLabel("Shake Parameters:", GREY, PADDING,yPos,sectionPanel)
	yPos = yPos + THIN_PAD + camera_shake_param:GetTall()

	local shakeAgressionSlider = vgui.Create( "DNumSlider", sectionPanel ) 
	shakeAgressionSlider:SetPos( PADDING,yPos ) 
	shakeAgressionSlider:SetSize( (sectionPanel:GetWide() / 2) - (2 * PADDING), 33 )
	shakeAgressionSlider:SetText( "Agression" ) 
	shakeAgressionSlider:SetMin( 0 )
	shakeAgressionSlider:SetMax( 170 )
	shakeAgressionSlider:SetDecimals( 1 )
	shakeAgressionSlider:SetConVar( "npc_mover_gun_shake_agression" )

	local shakeCentered = vgui.Create( "DCheckBoxLabel", sectionPanel )
	shakeCentered:SetPos(PADDING + shakeAgressionSlider:GetWide() + PADDING, yPos )
	shakeCentered:SetText( "Center about direction" )
	shakeCentered:SizeToContents()
	shakeCentered:SetConVar( "npc_mover_gun_shake_center" )
	shakeCentered:SetValue( 1 )
	yPos = yPos + (THIN_PAD * 2) + shakeAgressionSlider:GetTall()

	local shakeFrequencySlider = vgui.Create( "DNumSlider", sectionPanel ) 
	shakeFrequencySlider:SetPos( PADDING,yPos ) 
	shakeFrequencySlider:SetSize( (sectionPanel:GetWide() / 2) - (2 * PADDING), 33 )
	shakeFrequencySlider:SetText( "Frequency" ) 
	shakeFrequencySlider:SetMin( 0 )
	shakeFrequencySlider:SetMax( 50 )
	shakeFrequencySlider:SetDecimals( 1 )
	shakeFrequencySlider:SetConVar( "npc_mover_gun_shake_frequency" )
	
	local applyButton = vgui.Create( "DButton" , sectionPanel) 
	applyButton:SetText( "Apply" ) 
	applyButton:SetPos( PADDING + shakeFrequencySlider:GetWide() + PADDING, yPos) 
	applyButton:SetSize( (sectionPanel:GetWide() / 2) - (PADDING), 25 ) 
	applyButton.DoClick = function ()
		LocalPlayer():ConCommand( "npc_mover_gun_entitIDfromclient " .. callingEntity:EntIndex())
		LocalPlayer():ConCommand( "npc_mover_gun_functIDfromclient " .. CatmullRomCams.SToolMethods.ActorMover.FUNCTION_ID_UPDATE_CAMERANODE)
	end					 
	yPos = yPos + (THIN_PAD * 2) + applyButton:GetTall()

end

local function DisplayTriggerSection(callingEntity, sectionPanel)

	local yPos = THIN_PAD
	local create_link = CreateLabel("Create Link:", GREY, PADDING,yPos,sectionPanel)
	yPos = yPos + THIN_PAD + create_link:GetTall()
		
	local linkToActorPathButton = vgui.Create( "DButton" ) 
	linkToActorPathButton:SetParent( sectionPanel )
	linkToActorPathButton:SetText( "Create actor pathway trigger" ) 
	linkToActorPathButton:SetPos( PADDING, yPos) 
	linkToActorPathButton:SetSize(160,25)
	linkToActorPathButton.DoClick = function ()
		LocalPlayer():ConCommand( "npc_mover_gun_entitIDfromclient " .. callingEntity:EntIndex())
		LocalPlayer():ConCommand( "npc_mover_gun_toolstate " .. CatmullRomCams.SToolMethods.ActorMover.TOOLSTATE_LINKACTORCAMERAPATH)
		sectionPanel:GetParent():SetVisible(false)
	end		
	yPos = yPos + THIN_PAD + linkToActorPathButton:GetTall()
	
	local linkToPropButton = vgui.Create( "DButton" ) 
	linkToPropButton:SetParent( sectionPanel )
	linkToPropButton:SetText( "Create attachment to prop" ) 
	linkToPropButton:SetPos( PADDING, yPos) 
	linkToPropButton:SetSize(160,25)
	yPos = yPos + PADDING + linkToPropButton:GetTall()
	
	local remove_link = CreateLabel("Remove Link:", GREY, PADDING,yPos,sectionPanel)
	yPos = yPos + THIN_PAD + remove_link:GetTall()
			
	local link_list = vgui.Create( "DPanelList", sectionPanel) 
	link_list:SetPos( PADDING,yPos) 
	local nope, link_list_y = link_list:GetPos()
	link_list:SetSize( sectionPanel:GetWide() - (PADDING * 2), sectionPanel:GetTall() - link_list_y - PADDING)
	link_list:SetSpacing(1)
	link_list:SetPadding(1)
	link_list:EnableHorizontal(false)
	link_list:EnableVerticalScrollbar(true)	

  //Get linked items 
  
	local removeLinkFunc = function () 
	end
	link_list:AddItem(CreateButton("Remove " .. "Box", removeLinkFunc, sectionPanel:GetWide() - (PADDING * 2),15, false, link_list))
	
end


local function ShowCameraPathwayProperties(userMessage)

	local callingEntity = userMessage:ReadEntity()
	local screenPos = callingEntity:GetPos():ToScreen()
	local secPanel = nil

	local camerapathwayPropertiesDialog = vgui.Create( "DFrame" ) 
	camerapathwayPropertiesDialog:SetPos( screenPos.x - 200,screenPos.y + 30) 
	camerapathwayPropertiesDialog:SetSize( PADDING + CAT_WIDTH + PADDING + SEC_WIDTH + PADDING, HEIGHT ) 
	camerapathwayPropertiesDialog:SetTitle( "Properties")
	camerapathwayPropertiesDialog:SetVisible( true ) 
	camerapathwayPropertiesDialog:SetDraggable( false )
	camerapathwayPropertiesDialog:ShowCloseButton( true )
	camerapathwayPropertiesDialog:MakePopup() 
    
	ANCHOR_Y = ANCHOR_Y + 20
	
	local catList = vgui.Create( "DPanelList", camerapathwayPropertiesDialog ) 
	catList:SetPos( PADDING,TITLE_BAR_HEIGHT + PADDING ) 
	catList:SetSize( CAT_WIDTH, HEIGHT - (PADDING * 2) - TITLE_BAR_HEIGHT)
	catList:SetSpacing(1)
	catList:SetPadding(1)
	catList:EnableHorizontal(false)
	catList:EnableVerticalScrollbar(true)		 

	local rebuildSectionPanel = function()
		
		if secPanel then
			secPanel:SetVisible(false)
		end

		secPanel = vgui.Create( "DPanel", camerapathwayPropertiesDialog) 
		secPanel:SetPos( PADDING + CAT_WIDTH + PADDING,TITLE_BAR_HEIGHT + PADDING ) 
		secPanel:SetSize( SEC_WIDTH, HEIGHT - (PADDING * 2) - TITLE_BAR_HEIGHT )
		secPanel.Paint = function()
			surface.SetDrawColor(50,50,50,255)
			surface.DrawRect(0,0,secPanel:GetWide(),secPanel:GetTall())
		end
	end

	local frameFunc = function () 
		rebuildSectionPanel()
		secPanel:Clear()
		lastPropertiesSection = 1
		DisplayFramingSection(callingEntity,secPanel)
	end

	local propertiesFunc = function () 
		rebuildSectionPanel()
		lastPropertiesSection = 2
		DisplayPropertiesSection(callingEntity,secPanel)
	end

	local playbackFunc = function () 
		rebuildSectionPanel()
		lastPropertiesSection = 3
		DisplayPlaybackSection(callingEntity,secPanel)
	end

	local timeFunc = function () 
		rebuildSectionPanel()
		lastPropertiesSection = 4
		DisplayTimingSection(callingEntity,secPanel)
	end

	local displayFunc = function () 
		rebuildSectionPanel()
		lastPropertiesSection = 5
		DisplayDisplaySection(callingEntity,secPanel)
	end
	local phenomenaFunc = function () 
		rebuildSectionPanel()
		lastPropertiesSection = 6
		DisplayPhenomenaSection(callingEntity,secPanel)
	end
	local triggerFunc = function () 
		rebuildSectionPanel()
		lastPropertiesSection = 7
		DisplayTriggerSection(callingEntity,secPanel)
	end

	local closeFunc = function ()
		//Doing this ensures that data from slider controls is updated on server
		LocalPlayer():ConCommand( "npc_mover_gun_entitIDfromclient " .. callingEntity:EntIndex())
		LocalPlayer():ConCommand( "npc_mover_gun_functIDfromclient " .. CatmullRomCams.SToolMethods.ActorMover.FUNCTION_ID_UPDATE_CAMERANODE)
		
		camerapathwayPropertiesDialog:SetVisible(false)
	end

		catList:AddItem(CreateLabel("Camera Track",GREY, PADDING, ANCHOR_Y, catList))

		catList:AddItem(CreateButton("Playback", playbackFunc, CAT_WIDTH,15, false, catList))
		catList:AddItem(CreateButton("Framing", frameFunc, CAT_WIDTH,15, false, catList))

		catList:AddItem(CreateLabel("Camera Node",GREY, PADDING, ANCHOR_Y, catList))
		
		catList:AddItem(CreateButton("Time/Speed", timeFunc, CAT_WIDTH,15, false, catList))
		catList:AddItem(CreateButton("Display", displayFunc, CAT_WIDTH,15, false, catList))
		catList:AddItem(CreateButton("Phenomena", phenomenaFunc,CAT_WIDTH,15, false, catList))
		catList:AddItem(CreateButton("Triggers/Events", triggerFunc, CAT_WIDTH,15, false, catList))
	
		catList:AddItem(CreateLabel("General",GREY, PADDING, ANCHOR_Y, catList))
		catList:AddItem(CreateButton("Properties", propertiesFunc, CAT_WIDTH,15, false, catList))
		catList:AddItem(CreateButton("Close", closeFunc, CAT_WIDTH,15, false, catList))
	
	//Show last playback section
	if lastPropertiesSection == 1 then
		frameFunc()
	elseif lastPropertiesSection == 2 then
		propertiesFunc()
	elseif lastPropertiesSection == 3 then
		playbackFunc()
	elseif lastPropertiesSection == 4 then
		timeFunc()
	elseif lastPropertiesSection == 5 then
		displayFunc()
	elseif lastPropertiesSection == 6 then
		phenomenaFunc()
	else 
		triggerFunc()
	end


end

usermessage.Hook( "ShowProperties" .. "sent_camera", ShowCameraPathwayProperties) 


//local function ShowCameraPathwayProperties(userMessage)
//
//	local callingEntity = userMessage:ReadEntity()
//	local screenPos = callingEntity:GetPos():ToScreen()
//
//	if(camerapathwayPropertiesDialog) then
//		camerapathwayPropertiesDialog:SetVisible(true)
//	else
//		local PADDING = 9
//		local ANCHOR_Y = PADDING
//		local ANCHOR_X = PADDING
//		camerapathwayPropertiesDialog = vgui.Create( "DFrame" ) 
//		camerapathwayPropertiesDialog:SetPos( screenPos.x - 200,screenPos.y + 30) 
//		camerapathwayPropertiesDialog:SetSize( (4 * PADDING) + (3 * 150), 250 ) 
//		camerapathwayPropertiesDialog:SetTitle( "Properties")
//		camerapathwayPropertiesDialog:SetVisible( true ) 
//		camerapathwayPropertiesDialog:SetDraggable( false )
//		camerapathwayPropertiesDialog:ShowCloseButton( false )
//		camerapathwayPropertiesDialog:MakePopup() 
//	    
//		ANCHOR_Y = ANCHOR_Y + 20
//		
//		CreateLabel("Camera Track:",GREY, ANCHOR_X, ANCHOR_Y, camerapathwayPropertiesDialog)
//		ANCHOR_Y = ANCHOR_Y + 20
//
//		CreateLabel("Framing:",WHITE, ANCHOR_X, ANCHOR_Y, camerapathwayPropertiesDialog)
//		ANCHOR_Y = ANCHOR_Y + 20
//
//		local normalFrameButton = vgui.Create("DImageButton", camerapathwayPropertiesDialog) 
//		normalFrameButton:SetMaterial("gui/frame_tv")
//		normalFrameButton:SizeToContents()
//		normalFrameButton:SetPos(PADDING ,ANCHOR_Y)
//		normalFrameButton.DoClick = function () 
//			LocalPlayer():ConCommand( "npc_mover_gun_toolstate " .. TOOLSTATE_LINKACTORCAMERAPATH)
//			camerapathwayPropertiesDialog:SetVisible(false)
//		end
//		
//		local widescreenFrameButton = vgui.Create("DImageButton", camerapathwayPropertiesDialog) 
//		widescreenFrameButton:SetMaterial("gui/frame_widescreen")
//		widescreenFrameButton:SizeToContents()
//		widescreenFrameButton:SetPos(ANCHOR_X + normalFrameButton:GetWide() + PADDING,ANCHOR_Y)
//		widescreenFrameButton.DoClick = function () 
//			LocalPlayer():ConCommand( "npc_mover_gun_toolstate " .. TOOLSTATE_LINKACTORCAMERAPATH)
//			camerapathwayPropertiesDialog:SetVisible(false)
//		end
//		
//		local scopeFrameButton = vgui.Create("DImageButton", camerapathwayPropertiesDialog) 
//		scopeFrameButton:SetMaterial("gui/frame_scope")
//		scopeFrameButton:SizeToContents()
//		scopeFrameButton:SetPos(ANCHOR_X + normalFrameButton:GetWide() + PADDING + widescreenFrameButton:GetWide() + PADDING,ANCHOR_Y)
//		scopeFrameButton.DoClick = function () 
//			LocalPlayer():ConCommand( "npc_mover_gun_toolstate " .. TOOLSTATE_LINKACTORCAMERAPATH)
//			camerapathwayPropertiesDialog:SetVisible(false)
//		end
//		ANCHOR_Y = ANCHOR_Y + widescreenFrameButton:GetTall() + PADDING
//
//		CreateLabel("Playback control:",WHITE, ANCHOR_X, ANCHOR_Y, camerapathwayPropertiesDialog)
//		ANCHOR_Y = ANCHOR_Y + 20
//
//		cameraPlayButton = vgui.Create( "DImageButton", camerapathwayPropertiesDialog) 
//		cameraPlayButton:SetMaterial( "gui/control_play_final" ) 
//		cameraPlayButton:SizeToContents()
//		cameraPlayButton:SetPos( ANCHOR_X, ANCHOR_Y) 
//
//		cameraPreviewPlayButton = vgui.Create( "DImageButton", camerapathwayPropertiesDialog) 
//		cameraPreviewPlayButton:SetMaterial( "gui/control_play" ) 
//		cameraPreviewPlayButton:SizeToContents()
//		cameraPreviewPlayButton:SetPos( ANCHOR_X + 2 + cameraPlayButton:GetWide(), ANCHOR_Y) 
//
//		local cameraPreviewPauseButton = vgui.Create( "DImageButton", camerapathwayPropertiesDialog) 
//		cameraPreviewPauseButton:SetMaterial( "gui/control_pause" ) 
//		cameraPreviewPauseButton:SizeToContents()
//		cameraPreviewPauseButton:SetPos( ANCHOR_X + 2 + cameraPlayButton:GetWide() + PADDING / 2 + cameraPreviewPlayButton:GetWide(), ANCHOR_Y) 
//	
//		local cameraPreviewStopButton = vgui.Create( "DImageButton", camerapathwayPropertiesDialog) 
//		cameraPreviewStopButton:SetMaterial( "gui/control_stop" ) 
//		cameraPreviewStopButton:SizeToContents()
//		cameraPreviewStopButton:SetPos( ANCHOR_X + 2 + cameraPlayButton:GetWide() + 2 + cameraPreviewPlayButton:GetWide() + 2 + cameraPreviewPauseButton:GetWide(), ANCHOR_Y) 
//
//		ANCHOR_Y = ANCHOR_Y + 40
//
//		//cameraPlayButton = vgui.Create( "DButton" ) 
//		//cameraPlayButton:SetParent( camerapathwayPropertiesDialog ) // Set parent to our "DermaPanel" 
//		//cameraPlayButton:SetText( "Play" ) 
//		//cameraPlayButton:SetPos( ANCHOR_X, ANCHOR_Y) 
//		//cameraPlayButton:SetSize( 150, 25 ) 
//
//		//ANCHOR_Y = ANCHOR_Y + 30
//		cameraRangeButton = vgui.Create( "DButton" ) 
//		cameraRangeButton:SetParent( camerapathwayPropertiesDialog ) // Set parent to our "DermaPanel" 
//		cameraRangeButton:SetText( "Set Range Endpoint" ) 
//		cameraRangeButton:SetPos( ANCHOR_X, ANCHOR_Y) 
//		cameraRangeButton:SetSize( 150, 25 ) 
//  		cameraRangeButton.DoClick = function () 
//			cameraRangeButton:SetSelected( !cameraRangeButton:GetSelected() )
//		end
//		ANCHOR_Y = ANCHOR_Y + 30
//
//		CreateLabel("Misc:",WHITE, ANCHOR_X, ANCHOR_Y, camerapathwayPropertiesDialog)
//		ANCHOR_Y = ANCHOR_Y + 20
//
//		local viewScreenButton = vgui.Create( "DButton", camerapathwayPropertiesDialog ) 
//		viewScreenButton:SetText( "Toggle View Finder" ) 
//		viewScreenButton:SetPos( ANCHOR_X, ANCHOR_Y) 
//		viewScreenButton:SetSize( 150, 25 ) 
//		viewScreenButton.DoClick = function () 
//			viewScreenButton:SetSelected( !viewScreenButton:GetSelected() )
//		end
//  
//		////////////////////////////////////////////////////////////////////////////////////////////////////
//		////////////////////////////////////////////////////////////////////////////////////////////////////
//		//Set up right hand of panel
//		ANCHOR_Y = PADDING + 20
//		ANCHOR_X = 150 + PADDING + PADDING
//
//		CreateLabel("Camera Node:",GREY, ANCHOR_X, ANCHOR_Y, camerapathwayPropertiesDialog)
//		ANCHOR_Y = ANCHOR_Y + 20
//
//		CreateLabel("Timing:",WHITE, ANCHOR_X, ANCHOR_Y, camerapathwayPropertiesDialog)
//		ANCHOR_Y = ANCHOR_Y + 20
//
//		local transitionTimeSlider = vgui.Create( "DNumSlider", camerapathwayPropertiesDialog ) 
//		transitionTimeSlider:SetPos( ANCHOR_X,ANCHOR_Y ) 
//		transitionTimeSlider:SetSize( 150, 35 )
//		transitionTimeSlider:SetText( "Transition" ) 
//		transitionTimeSlider:SetMin( 0 )
//		transitionTimeSlider:SetMax( 1000 )
//		transitionTimeSlider:SetDecimals( 2 )
//		transitionTimeSlider:SetConVar( "camera_node_transition" )
//		ANCHOR_Y = ANCHOR_Y + 40
//
//		local nodeTimeSlider = vgui.Create( "DNumSlider", camerapathwayPropertiesDialog ) 
//		nodeTimeSlider:SetPos( ANCHOR_X,ANCHOR_Y ) 
//		nodeTimeSlider:SetSize( 150, 35 )
//		nodeTimeSlider:SetText( "Wait time" ) 
//		nodeTimeSlider:SetMin( 0 )
//		nodeTimeSlider:SetMax( 1000 )
//		nodeTimeSlider:SetDecimals( 2 )
//		nodeTimeSlider:SetConVar( "camera_node_wait" )
//		ANCHOR_Y = ANCHOR_Y + 50
//
//		CreateLabel("Effects:",WHITE, ANCHOR_X, ANCHOR_Y, camerapathwayPropertiesDialog)
//		ANCHOR_Y = ANCHOR_Y + 20
//
//		local cameraZoomSlider = vgui.Create( "DNumSlider", camerapathwayPropertiesDialog ) 
//		cameraZoomSlider:SetPos( ANCHOR_X,ANCHOR_Y ) 
//		cameraZoomSlider:SetSize( 150, 35 )
//		cameraZoomSlider:SetText( "camera_zoom" ) 
//		cameraZoomSlider:SetMin( 0 )
//		cameraZoomSlider:SetMax( 100 )
//		cameraZoomSlider:SetDecimals( 1 )
//		cameraZoomSlider:SetConVar( "camera_node_zoom" )
//		ANCHOR_Y = ANCHOR_Y + 40
//
//		cameraShakeSlider = vgui.Create( "DNumSlider", camerapathwayPropertiesDialog ) 
//		cameraShakeSlider:SetPos( ANCHOR_X,ANCHOR_Y ) 
//		cameraShakeSlider:SetSize( 150, 35 )
//		cameraShakeSlider:SetText( "Random Shake" ) 
//		cameraShakeSlider:SetMin( 0 )
//		cameraShakeSlider:SetMax( 100 )
//		cameraShakeSlider:SetValue( 0.0 )
//		cameraShakeSlider:SetDecimals( 1 )
//		cameraShakeSlider:SetConVar( "camera_node_shake" )	
//		LocalPlayer():ConCommand( "npc_mover_gun_camera_node_shake 0.0")
//			
//		ANCHOR_Y = ANCHOR_Y + 40
////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////////////////////////////////////////////////////////////
//		ANCHOR_Y = PADDING + 20
//		ANCHOR_X = 150 + PADDING + 150 + PADDING + PADDING 
//
//		CreateLabel("Camera Node:",GREY, ANCHOR_X, ANCHOR_Y, camerapathwayPropertiesDialog)
//		ANCHOR_Y = ANCHOR_Y + 20
//
//		CreateLabel("Event/Trigger Setup:",WHITE, ANCHOR_X, ANCHOR_Y, camerapathwayPropertiesDialog)
//		ANCHOR_Y = ANCHOR_Y + 20
//		
//		linkToActorPathButton = vgui.Create( "DButton" ) 
//		linkToActorPathButton:SetParent( camerapathwayPropertiesDialog ) // Set parent to our "DermaPanel" 
//		linkToActorPathButton:SetText( "Link to Actor Pathway" ) 
//		linkToActorPathButton:SetPos( ANCHOR_X, ANCHOR_Y) 
//		linkToActorPathButton:SetSize( 150, 25 ) 
//		
//		ANCHOR_Y = ANCHOR_Y + 30
//		closeButton = vgui.Create( "DButton" ) 
//		closeButton:SetParent( camerapathwayPropertiesDialog ) // Set parent to our "DermaPanel" 
//		closeButton:SetText( "Close" ) 
//		closeButton:SetPos( ANCHOR_X, ANCHOR_Y) 
//		closeButton:SetSize( 150, 25 ) 
//
//
//
//	end   
//	
//	if closeButton then
//
//		cameraShakeSlider:SetValue(callingEntity:GetNWFloat("camera_node_shake"))
//
//		closeButton.DoClick = function () 
//		
//			callingEntity:SetNWFloat("camera_node_shake", cameraShakeSlider:GetValue())
//			//cameraShakeSlider:SetValue(0.0)
//			//LocalPlayer():ConCommand( "npc_mover_gun_camera_node_shake 0.0")
//			camerapathwayPropertiesDialog:SetVisible(false)
//		end
//	end
//
//	if cameraPlayButton then
//		cameraPlayButton.DoClick = function () 
//		
//			//Need to put the tool back into idle state so that its 'Think()' will process the
//			//function request to 'play' the camera
//			LocalPlayer():ConCommand( "npc_mover_gun_toolstate " .. CatmullRomCams.SToolMethods.ActorMover.TOOLSTATE_IDLE)
//			LocalPlayer():ConCommand( "npc_mover_gun_entitIDfromclient " .. callingEntity:EntIndex())
//			LocalPlayer():ConCommand( "npc_mover_gun_functIDfromclient " .. CatmullRomCams.SToolMethods.ActorMover.FUNCTION_ID_PLAY)
//			camerapathwayPropertiesDialog:SetVisible(false)
//		end
//	end
//
//	if linkToActorPathButton then
//		linkToActorPathButton.DoClick = function () 
//			if CatmullRomCams.SToolMethods.ActorMover.IsCameraNode(callingEntity) then
//				LocalPlayer():ConCommand( "npc_mover_gun_entitIDfromclient " .. callingEntity:EntIndex())
//				LocalPlayer():ConCommand( "npc_mover_gun_toolstate " .. CatmullRomCams.SToolMethods.ActorMover.TOOLSTATE_LINKACTORCAMERAPATH)
//			else
//				PrintError(7)
//				selectedNPCPathNode = nil
//				LocalPlayer():ConCommand( "npc_mover_gun_toolstate " .. CatmullRomCams.SToolMethods.ActorMover.TOOLSTATE_IDLE)
//			end
//			camerapathwayPropertiesDialog:SetVisible(false)
//		end
//	end
//end
